import {Component, OnInit} from '@angular/core';
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
import {Farm} from '../../../entity/farm.model';
import {ApplicationService} from '../../../service/application.service';
import {ParamDict} from '../../../entity/menu-param-dict.model';

@Component({
  selector: 'app-station',
  templateUrl: './station.component.html',
  styleUrls: ['./station.component.css']
})
export class StationComponent implements OnInit {
  /**
   * 当前风场下标
   *
   * @type {number}@memberof StationComponent
   */
  public active: number = 0;
  /**
   * 当前选中风场id
   *
   * @type {number}@memberof StationComponent
   */
  private selectedValue: number;
  /**
   * 风场列表
   *
   * @type {string}@memberof StationComponent
   */
  public farms: Farm[] = [];
  private url: string[] = []
  srcUrl: any;
  currentMenuParams: ParamDict;
  currentParamsNames: string[] = [];

  constructor(
    private sanitizer: DomSanitizer,
    private application: ApplicationService,
  ) {

  }

  ngOnInit() {
    this.farms = this.application.currentUserFarms.filter(farm => farm.farmCategory === 'winfarm');
    if (this.application.currentMenuParams) {
      this.currentMenuParams = this.application.currentMenuParams;
      this.currentParamsNames = Object.getOwnPropertyNames(this.currentMenuParams);
      this.currentParamsNames.forEach(farmName => {
        this.url.push(this.application.appConfigData.appStation + '/' + this.application.currentMenuParams[farmName].paramValue);
      });
      this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
        this.url[this.active]);
    }
  }

  onClick(index, farmName) {
    this.active = index;
    this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url[this.active]);
  }
}


// WEBPACK FOOTER //
// ./src/app/module/monitor/station/station.component.ts
